package com.bw.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author Lenovo
 * @date 2025年08月29日 10:48
 */
@RestController
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;

    @RequestMapping("/s1")
    public JSONObject select1(){
        JSONObject result=new JSONObject();

        result.put("status",0);
        result.put("msg","");

        JSONObject data = new JSONObject();
        result.put("data",data);

        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();

        data.put("columns",columns);
        data.put("rows",rows);

        JSONObject c1=new JSONObject();
        c1.put("id","cta");
        c1.put("name","下单金额");

        JSONObject c2=new JSONObject();
        c2.put("id","ctb");
        c2.put("name","下单次数");

        JSONObject c3=new JSONObject();
        c3.put("id","ctc");
        c3.put("name","下单人数");

        JSONObject c4=new JSONObject();
        c4.put("id","ctd");
        c4.put("name","实收金额");

        JSONObject c5=new JSONObject();
        c5.put("id","cte");
        c5.put("name","退款成功金额");

        columns.add(c1);
        columns.add(c2);
        columns.add(c3);
        columns.add(c4);
        columns.add(c5);
        List<Map<String, Object>> maps = orderInfoService.select1();
        for (Map<String, Object> map : maps) {
            JSONObject row=new JSONObject();
            row.put("cta",map.get("cta"));
            row.put("ctb",map.get("ctb"));
            row.put("ctc",map.get("ctc"));
            row.put("ctd",map.get("ctd"));
            row.put("cte",map.get("cte"));
            rows.add(row);
        }
        return result;
    }

    @RequestMapping("/s2")
    public JSONObject select2(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");

        JSONObject data = new JSONObject();
        result.put("data",data);

        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();
        data.put("columns",columns);
        data.put("rows",rows);

        JSONObject col1 = new JSONObject();
        col1.put("id","cta");
        col1.put("name","直营店优惠分摊支出金额");

        JSONObject col2 = new JSONObject();
        col2.put("id","ctb");
        col2.put("name","加盟店优惠分摊支出金额");

        columns.add(col1);
        columns.add(col2);
        List<Map<String, Object>> maps = orderInfoService.select2();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("cta",map.get("cta"));
            row.put("ctb",map.get("ctb"));
            rows.add(row);
        }

        return result;
    }

    @RequestMapping("/s3")
    public JSONObject select3(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");

        JSONObject data = new JSONObject();
        result.put("data",data);

        JSONArray categories = new JSONArray();
        JSONArray series = new JSONArray();

        data.put("categories",categories);
        data.put("series",series);

        JSONObject series_row1 = new JSONObject();
        series_row1.put("name","评价次数");
        series.add(series_row1);

        JSONArray series_data1 = new JSONArray();
        series_row1.put("name",series_data1);


        List<Map<String, Object>> maps = orderInfoService.select3();
        for (Map<String, Object> map : maps) {
            categories.add(map.get("cta"));
        }


        return result;
    }

    @RequestMapping("/s4")
    public JSONObject select4() {
        JSONObject result = new JSONObject();
        result.put("status", 0);
        result.put("msg", "");

        JSONObject data = new JSONObject();
        result.put("data", data);

        JSONArray categories = new JSONArray();
        JSONArray series = new JSONArray();

        data.put("categories", categories);
        data.put("series", series);

        JSONObject series_row1 = new JSONObject();
        series_row1.put("name", "下单金额");
        series.add(series_row1);


        JSONArray series_data1 = new JSONArray();
        series_row1.put("data", series_data1);

        JSONArray series_data2 = new JSONArray();
        series_row1.put("data", series_data2);

        JSONArray series_data3 = new JSONArray();
        series_row1.put("data", series_data3);

        List<Map<String, Object>> maps = orderInfoService.select4();
        for (Map<String, Object> map : maps) {
            categories.add(map.get("day"));
            series_data1.add(map.get("cta"));
            series_data2.add(map.get("ctb"));
            series_data3.add(map.get("ctc"));
        }


        return result;

    }
}
